home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / INTLDEMO.PAK / CALLDEMO.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  211 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1996 by Borland International
  3. //   calldemo.cpp
  4. //
  5. //----------------------------------------------------------------------------
  6.  
  7. #include <owl/applicat.h>
  8. #include <owl/framewin.h>
  9. #include <owl/dialog.h>
  10. #include <owl/radiobut.h>
  11. #include <owl/groupbox.h>
  12. #include <owl/combobox.h>
  13. #include "calldemo.h"
  14. #pragma hdrstop
  15. #include "intldemo.cxx"
  16.  
  17. #define ExeProgId "Locale.Application"
  18. TPointer<TLocaleApplication> intldemo;          // smart pointer to object representing the server application
  19.  
  20. typedef void (TLocaleWindow::*ClassFunction)(); // define pointer to member function of proxy class
  21.  
  22. const int MAX_CLASSIFICATION_NAME = 20;         // length of buffer used to load names of
  23.                                                                 // classification functions, e.g. "isalpha()"
  24. //
  25. // class TIntlDemoGroup
  26. // ----- --------------
  27. //
  28. // Associated with group boxes which control the UI language and the
  29. // locale used by intldemo.
  30. // 
  31. class TIntlDemoGroup : public TGroupBox
  32. {
  33.      TLocaleFrame* LocaleFrame;
  34.  
  35.   public:
  36.      TIntlDemoGroup(TWindow* parent, int resourceId, TLocaleFrame* localeFrame) 
  37.                         : TGroupBox(parent, resourceId) 
  38.      {
  39.         LocaleFrame = localeFrame;
  40.      }
  41.  
  42.      void SelectionChanged(int controlId);
  43. };
  44.  
  45. void TIntlDemoGroup::SelectionChanged(int controlId)
  46. {
  47.   switch (controlId) {
  48.      case IDC_ENGLISH:
  49.         LocaleFrame->EnglishLanguage();
  50.         break;
  51.         
  52.      case IDC_GERMAN:
  53.         LocaleFrame->GermanLanguage();
  54.         break;
  55.         
  56.      case IDC_FRENCH:
  57.         LocaleFrame->FrenchLanguage();
  58.         break;
  59.      case IDC_CLOCALE:
  60.         LocaleFrame->CLocale();
  61.         break;
  62.         
  63.      case IDC_USLOCALE:
  64.         LocaleFrame->USLocale();
  65.         break;
  66.         
  67.      case IDC_UKLOCALE:
  68.         LocaleFrame->UKLocale();
  69.         break;
  70.         
  71.      case IDC_FRALOCALE:
  72.         LocaleFrame->FrenchLocale();
  73.         break;
  74.         
  75.      case IDC_GERLOCALE:
  76.         LocaleFrame->GermanLocale();
  77.         break;
  78.   }
  79. }
  80. //
  81. // class TCallDemoDlg
  82. // ----- ------------
  83. //
  84. // Defines the dialog box which is used as the main window of the
  85. // controller application.
  86. //
  87. class TCallDemoDlg : public TDialog
  88. {
  89.   public:
  90.      TCallDemoDlg(TWindow*, TResId);
  91.  
  92.   protected:
  93.   
  94.      TIntlDemoGroup *Language;
  95.      TIntlDemoGroup *Locale;
  96.      
  97.      TRadioButton *English, *French, *German;
  98.      TRadioButton *CLocale, *USLocale, *UKLocale;
  99.      TRadioButton *FraLocale, *GerLocale;
  100.      TComboBox* Classification;
  101.  
  102.      TLocaleFrame LocaleFrame;
  103.      TLocaleWindow LocaleWindow;
  104.  
  105.      void SetupWindow();
  106.      void ClassificationChange();
  107.      static const ClassFunction ClassificationFunctions[];
  108.      
  109.      DECLARE_RESPONSE_TABLE(TCallDemoDlg);
  110. };
  111.  
  112. DEFINE_RESPONSE_TABLE1(TCallDemoDlg, TDialog)
  113.   EV_CBN_SELCHANGE(IDC_CLASSIFICATION, ClassificationChange),
  114. END_RESPONSE_TABLE;
  115.  
  116. const ClassFunction TCallDemoDlg::ClassificationFunctions[] =
  117.   { TLocaleWindow::IsAlnum, TLocaleWindow::IsAlpha, TLocaleWindow::IsAscii, TLocaleWindow::IsCntrl,
  118.      TLocaleWindow::IsDigit, TLocaleWindow::IsGraph, TLocaleWindow::IsLower, TLocaleWindow::IsPrint, 
  119.      TLocaleWindow::IsPunct, TLocaleWindow::IsSpace, TLocaleWindow::IsUpper, TLocaleWindow::IsXDigit };
  120.  
  121. void TCallDemoDlg::SetupWindow()
  122. {
  123.  
  124.   TDialog::SetupWindow();
  125.   
  126.   char buf[MAX_CLASSIFICATION_NAME];
  127.   for (int i=IDS_ISALNUM; i<=IDS_ISXDIGIT; i++) {
  128.      GetApplication()->LoadString(i, buf, sizeof(buf));
  129.      Classification->AddString(buf);
  130.   }
  131.   
  132.   English->Check();                // select English UI
  133.   CLocale->Check();                // select C Locale
  134.   Classification->SetSelIndex(1);  // select isalpha()
  135. }
  136.  
  137. TCallDemoDlg::TCallDemoDlg(TWindow* parent, TResId resId)
  138.                 : TDialog(parent, resId), TWindow(parent)
  139. {
  140.   intldemo->Bind(ExeProgId);
  141.   intldemo->GetWindow(LocaleFrame);
  142.      
  143.   LocaleFrame.EnglishLanguage();   // set to English UI
  144.   LocaleFrame.CLocale();           // set to C Locale 
  145.   LocaleFrame.GetWindow(LocaleWindow);
  146.   LocaleWindow.IsAlpha();          // set to isalpha()
  147.  
  148.   Language = new TIntlDemoGroup(this, IDC_LANGUAGE, &LocaleFrame);
  149.   English = new TRadioButton(this, IDC_ENGLISH, Language);
  150.   French = new TRadioButton(this, IDC_FRENCH, Language);
  151.   German = new TRadioButton(this, IDC_GERMAN, Language);
  152.  
  153.   Locale = new TIntlDemoGroup(this, IDC_LOCALE, &LocaleFrame);
  154.   CLocale = new TRadioButton(this, IDC_CLOCALE, Locale);
  155.   USLocale = new TRadioButton(this, IDC_USLOCALE, Locale);
  156.   UKLocale = new TRadioButton(this, IDC_UKLOCALE, Locale);
  157.   FraLocale = new TRadioButton(this, IDC_FRALOCALE, Locale);
  158.   GerLocale = new TRadioButton(this, IDC_GERLOCALE, Locale);
  159.  
  160.   Classification = new TComboBox(this, IDC_CLASSIFICATION);
  161. }
  162.  
  163. void TCallDemoDlg::ClassificationChange()
  164. {
  165.   int sel = Classification->GetSelIndex();
  166.   if (sel>=0)
  167.      (LocaleWindow.*ClassificationFunctions[sel])();
  168. }
  169.  
  170. //
  171. // class TCallDemoApp
  172. // ----- ------------
  173. //
  174. // Application class.
  175. //
  176. class TCallDemoApp : public TApplication
  177. {
  178.   private:
  179.      TLocaleApplication* IntlDemo;
  180.  
  181.   public:
  182.      TCallDemoApp() : TApplication() { }
  183.  
  184.      void InitMainWindow()
  185.      {
  186.         TFrameWindow* frame = new TFrameWindow(0, "Call IntlDemo Program",
  187.                                      new TCallDemoDlg(0, CALLDEMODLG), true );
  188.  
  189.         SetMainWindow(frame);
  190.         MainWindow->SetIcon(this, TResId("CONTROL"));
  191.         MainWindow->Attr.Style &= ~(WS_MAXIMIZEBOX | WS_THICKFRAME);
  192.      }
  193. };
  194.  
  195. int OwlMain(int /* argc */, char* /* argv */ [])
  196. {
  197.   TOleAllocator OleAloc(0);
  198.  
  199.   intldemo = new TLocaleApplication;
  200.  
  201.   try {
  202.      TCallDemoApp().Run();
  203.      intldemo->Quit();
  204.      return 0;
  205.   }
  206.   catch (TXBase& x) {
  207.      MessageBox(0, x.why().c_str(), "Reason", MB_OK);
  208.   }
  209.   return -1; 
  210. }
  211.